              package com.java.diagnostics.visualizer.impl.extensions;
              
              import com.java.diagnostics.visualizer.impl.factory.LogFactory;
              import com.java.diagnostics.visualizer.impl.util.Messages;
              import java.util.ArrayList;
              import java.util.List;
              import java.util.logging.Level;
              import java.util.logging.Logger;
              import org.eclipse.core.runtime.IConfigurationElement;
              import org.eclipse.core.runtime.IExtension;
              import org.eclipse.core.runtime.IExtensionPoint;
              import org.eclipse.core.runtime.IExtensionRegistry;
              import org.eclipse.core.runtime.Platform;
              
              public abstract class GCAndMemoryVisualizerExtensionRegistry
              {
                public static final String CLASS = "class";
                private static final Logger TRACE = LogFactory.getTrace(GCAndMemoryVisualizerExtensionRegistry.class);
                private static final String LABEL = "label";
                public static final String NAME = "name";
                public static final String ENABLED_BY_DEFAULT = "enabledByDefault";
                private IExtension[] extensions = null;
              
                public IExtension[] getExtensions()
                {
                  if (this.extensions == null) {
                    IExtensionRegistry registry = Platform.getExtensionRegistry();
              
                    if (registry != null) {
                      IExtensionPoint extensionPoint = registry
                        .getExtensionPoint(getExtensionPointID());
              
                      if (extensionPoint != null) {
                        this.extensions = extensionPoint.getExtensions();
                      }
                    }
                  }
              
                  return this.extensions == null ? null : (IExtension[])this.extensions.clone();
                }
              
                public IConfigurationElement findExtensionByClassName(String className)
                {
                  IExtension[] extensions = getExtensions();
                  if (extensions != null)
                  {
                    for (int i = 0; i < extensions.length; i++)
                    {
                      IExtension extension = extensions[i];
                      IConfigurationElement[] elements = extension
                        .getConfigurationElements();
              
                      for (int j = 0; j < elements.length; j++) {
                        IConfigurationElement element = elements[j];
                        TRACE.finer("Inspecting element: " + element.toString());
              
                        if (element.getAttribute("class").equals(className)) {
                          return element;
                        }
                      }
                    }
                  }
              
                  return null;
                }
              
                protected abstract String getExtensionPointID();
              
                protected List instantiateExtensions() {
                  IExtension[] extensions = getExtensions();
                  List classes = new ArrayList();
              
                  if (extensions != null) {
                    for (int i = 0; i < extensions.length; i++)
                    {
                      IExtension extension = extensions[i];
                      TRACE.finer("Inspecting extension: " + extension);
                      IConfigurationElement[] elements = extension
                        .getConfigurationElements();
              
                      for (int j = 0; j < elements.length; j++) {
                        IConfigurationElement element = elements[j];
                        TRACE.finer("Inspecting element: " + element.toString());
              
                        if (TRACE.isLoggable(Level.FINEST)) {
                          String[] names = element.getAttributeNames();
                          for (int n = 0; n < names.length; n++) {
                            TRACE.finest("Attribute name: " + names[n]);
                          }
              
                        }
              
                        String className = element.getAttribute("class");
                        try
                        {
                          Object executableExtension = element
                            .createExecutableExtension("class");
              
                          classes.add(executableExtension);
                          TRACE.finer("Extension is " + className);
                        } catch (Throwable c) {
                          TRACE
                            .warning(
                            Messages.getString("GCAndMemoryVisualizerExtensionRegistry.extension.instantiation.warning") + 
                            className + "." + c.getMessage());
                        }
                      }
                    }
                  }
              
                  return classes;
                }
              
                public String[] getNames() {
                  IExtension[] extensions = getExtensions();
                  if (extensions != null) {
                    String[] names = new String[extensions.length];
              
                    for (int i = 0; i < extensions.length; i++)
                    {
                      IExtension extension = extensions[i];
                      IConfigurationElement[] elements = extension
                        .getConfigurationElements();
              
                      for (int j = 0; j < elements.length; j++) {
                        IConfigurationElement element = elements[j];
              
                        names[i] = element.getAttribute("label");
                      }
                    }
                    return names;
                  }
                  return null;
                }
              }

